package link;


/**
 * 使用链表来模拟栈
 * Created by zhaoxin on 2018/7/22.
 */
public class LinkedListStack implements Stack{

    private LinkedList linkedList;

    public LinkedListStack(){
        linkedList = new LinkedList();
    }

    @Override
    public int getSize() {
        return linkedList.getSize();
    }

    @Override
    public boolean isEmpty() {
        return linkedList.isEmpty();
    }

    @Override
    public Object pop() {
        return linkedList.removeFirst();
    }

    @Override
    public Object peek() {
        return linkedList.getFirst();
    }

    @Override
    public void push(Object o) {
        linkedList.addFirst(o);
    }

    @Override
    public String toString() {
        return "LinkedListStack{" +
                "linkedList=" + linkedList +
                '}';
    }


    public static void main(String[] args) {
        LinkedListStack linkedListStack = new LinkedListStack();

        for (int i = 0; i < 10; i++) {
            linkedListStack.push(i);
        }
        linkedListStack.pop();
        System.out.println(linkedListStack.peek());
        System.out.println(linkedListStack);
    }
}
